﻿using System;
using System.Windows.Forms;
using System.Collections.Generic;
using HR60_PanelSoft.View.Base;
using HR60_PanelSoft.View.TabForms;


namespace HR60_PanelSoft.View.Controls
{
    //GC: [g1]bug2189/2190[FormTextBox]
    //GC: [g2]优化：将核心的基础控件传递到外层[FormTextBox]
    //GC: [g3]优化：4bug2205，优化FormTextBox的响应机制
	public class FormTextBox : BaseFormControl
	{
		private TextBox textBox = new TextBox();
		
		public FormTextBox()
		{
			textBox.Margin = new Padding(0);
			textBox.Dock = DockStyle.Fill;

            /* [g1.s1] */
			//textBox.TextChanged += new EventHandler(valueChange);
            //textBox.TextChanged += new EventHandler(valueChange_Normal);

            /* [g3.s1]更改事件响应机制 */
            //textBox.TextChanged += new EventHandler((object sender, EventArgs e) =>
            //    {
            //        ValueChangedEventArgs vcea = new ValueChangedEventArgs(EventType.FormTextBox);
            //        valueChange(sender, vcea);
            //    });
            textBox.KeyPress += new KeyPressEventHandler((object sender, KeyPressEventArgs kpea) =>
                {
                    if (kpea.KeyChar == 0x0D)
                    {
                        ValueChangedEventArgs vcea = new ValueChangedEventArgs(EventType.FormTextBox);
                        valueChange(sender, vcea);
                    }
                });

            /* end of [g3.s1] */
            /* end of [g1.s1] */


			this.AutoSize = false;
			this.Width = 100;
			this.Height = 21;
			this.Controls.Add(textBox);
		}

		// 重写Value属性
		public override object Value
		{
			get
			{
				return textBox.Text;
			}
			set
			{
				textBox.Text = value == null ? null : value.ToString();
			}
		}

        /* [g2.s1] */

        public override List<Control> GetCoreControls()
        {
            List<Control> rst = new List<Control>();
            rst.Clear();
            rst.Add(textBox);
            return rst;
        }

        /* end of [g2.s1] */

	}
}
